package auctionhaus

import org.junit.*
import grails.test.mixin.*


/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Customer)
class CustomerTests {

	Customer customer;

	@Before
	void setUp() {

		customer = new Customer();
	}

	@After
	void tearDown() {
		// Tear down logic here
	}

	/**************************************************************
	 * C-1: Customers have email address, password and created date 
	 * fields (unit test)
	 **************************************************************/

	void testFieldsExist(){

		assertFalse(customer.validate(['username']));
		assertFalse(customer.validate(['password']));
		assertTrue(customer.validate(['dateCreated']));

		customer.username = "mark@live.com"
		customer.password = "computer"

		assertTrue(customer.validate(['username']));
		assertTrue(customer.validate(['password']));
		assertTrue(customer.validate(['dateCreated']));
	}

	/**************************************************************
	 * C3: Email address must be of a valid form (@.*) (unit test) 
	 **************************************************************/

	//C-3: Email address must be of a valid form (@.*) (unit test)
	void testValidEmail(){
		customer.username = "asdf@asdf.com";
		assertTrue(customer.validate(['username']));
	}
	//C-3: Email address must be of a valid form (@.*) (unit test)
	void testInvalidEmailNoAtSymbol(){
		customer.username = "aaaaafff.com";
		assertFalse(customer.validate(['username']));
	}

	//C-3: Email address must be of a valid form (@.*) (unit test)
	void testInvalidEmailNothingBeforeAtSymbol(){
		customer.username = "@aaaaafff.com";
		assertFalse(customer.validate(['username']));
	}
	//C-3: Email address must be of a valid form (@.*) (unit test)
	void testInvalidEmailNothingAfterAtSymbol(){
		customer.username = "adfasdf@";
		assertFalse(customer.validate(['username']));
	}
	//C-3: Email address must be of a valid form (@.*) (unit test)
	void testInvalidEmailNoExtension(){
		customer.username = "adfasdf@adfadsf";
		assertFalse(customer.validate(['username']));
	}
	//C-3: Email address must be of a valid form (@.*) (unit test)
	void testInvalidEmailOnlyExtensionAfterAtSymbol(){
		customer.username = "adfasdf@.com";
		assertFalse(customer.validate(['username']));
	}
	//C-3: Email address must be of a valid form (@.*) (unit test)
	void testInvalidEmailOnlyText(){
		customer.username = "adfasdffffasdsdf";
		assertFalse(customer.validate(['username']));
	}

	/***********************************************************
	 * C-4: Password must be between 6-8 characters (unit test)
	 ************************************************************/

	//C-4: Password must be between 6-8 characters (unit test)
	void testValidPassword6(){
		customer.password = "thisis"
		assertTrue(customer.validate(['password']));
	}
	//C-4: Password must be between 6-8 characters (unit test)
	void testValidPassword7(){
		customer.password = "thisisa"
		assertTrue(customer.validate(['password']));
	}
	//C-4: Password must be between 6-8 characters (unit test)
	void testValidPassword8(){
		customer.password = "thisisap"
		assertTrue(customer.validate(['password']));
	}
	//C-4: Password must be between 6-8 characters (unit test)
//	void testInvalidPassword5(){
//		customer.password = "thisi"
//		assertFalse(customer.validate(['password']));
//	}
	//C-4: Password must be between 6-8 characters (unit test)
//	void testInvalidPassword9(){
//		customer.password = "thisisapa"
//		assertFalse(customer.validate(['password']));
//	}
	//C-4: Password must be between 6-8 characters (unit test)
	void testValidPasswordCapitalized(){
		customer.password = "THISISA"
		assertTrue(customer.validate(['password']));
	}
	//C-4: Password must be between 6-8 characters (unit test)
	void testValidPasswordCamelCase(){
		customer.password = "ThisIsA"
		assertTrue(customer.validate(['password']));
	}
	//C-4: Password must be between 6-8 characters (unit test)
	void testInvalidNullPassword(){
		customer.password = null
		assertFalse(customer.validate(['password']));
	}
	//C-4: Password must be between 6-8 characters (unit test)
	void testInvalidEmptyPassword(){
		customer.password = ""
		assertFalse(customer.validate(['password']));
	}
}
